package org.dtrd.modules.record.entity.po;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.record.entity.bean.SigninSuggestBean;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 打卡建议
 * </p>
 *
 * @author QR
 * @since 2021-10-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("dtrd_ent_rd_signin_suggest")
@Slf4j
public class DtrdEntRdSigninSuggest implements Serializable {


    @TableId(value = "data_id", type = IdType.AUTO)
    private Integer dataId;

    @TableField("patient_id")
    private Integer patientId;

    /**
     * 记录日期
     */
    private Date recordDate;

    /**
     * 记录时间
     */
    @TableField("record_time")
    private Date recordTime;

    /**
     * 打卡项目:1 血糖；2血压；3运动；4用药；5 饮食；6 体重；7腰围；8尿酮；9 胰岛素；10睡眠；11营养素
     */
    @TableField("signin_type")
    private Integer signinType;

    /**
     * 建议内容
     */
    @TableField("suggest_content")
    private String suggestContent;

    @TableField("create_time")
    private Date createTime;

    @TableField("create_by")
    private String creatBy;

    @TableField("update_time")
    private Date updateTime;

    @TableField("update_by")
    private Integer updateBy;

    @TableField("is_del")
    @TableLogic
    private Integer isDel;

    @TableField(exist = false)
    private String signinTypeText;

    public DtrdEntRdSigninSuggest init() {
        this.setRecordTime(new Date());
        this.setCreateTime(new Date());
        this.setRecordDate(new Date());
        this.setIsDel(0);
        return this;
    }

    public DtrdEntRdSigninSuggest parseFromDTO(SigninSuggestBean dto){
        this.setDataId(dto.getDataId());
        this.setSigninType(dto.getSigninType());
        this.setPatientId(dto.getPatientId());
        this.setSuggestContent(dto.getSuggestContent());
        try {
            if (dto.getRecordDate() != null) {
                this.setRecordTime(DateUtils.parseDate(dto.getRecordDate(), DateUtils.datetimeFormat.get().toPattern()));
                this.setRecordDate(DateUtils.parseDate(dto.getRecordDate(), DateUtils.date_sdf.get().toPattern()));
            }
        } catch (ParseException e) {
            log.error("DtrdEntRdSigninSuggest.parseFromDTO recordTime转换失败, {}", e.getMessage());
            e.printStackTrace();
        }
        this.setCreatBy(dto.getCreateBy());
        this.setCreateTime(dto.getCreatTime());
        return this;
    }

}
